package com.springcloud.alibaba.controller;


import com.springcloud.albaba.common.entity.Commentresult;
import com.springcloud.albaba.common.entity.Payment;
import com.springcloud.alibaba.service.PaymentSerice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author:RenPu
 * @Date: 2020/6/28 16:30
 * @Version: 1.0
 * @description:
 */

@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentSerice paymentSerice;


    @PostMapping("/Payment/create")
    public Commentresult create(Payment payment){
        int result = paymentSerice.create(payment);
        log.info( "********* 出入成功sdfgdfgsfgsfsd"+result);

        if (result>0){
          return new Commentresult(200,"数据库插入成功",result);
        }else {
            return new Commentresult(400,"数据库插入失败",null);
        }
    }

    @GetMapping(value = "/Payment/selectPaymentById/{id}")
    public Commentresult selectPaymentById(@PathVariable(value = "id") long id){
        Payment payment = paymentSerice.selectPaymentById( id );

        log.info( "********* 获取结果"+payment);

        if (payment!=null){
            return new Commentresult(200,"数据库获取成功",payment);
        }else {
            return new Commentresult(400,"没有对应记录，查询ID:"+id,null);
        }
    }
}
